/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.teama;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author xiopus
 */
@WebServlet(name = "editIssue", urlPatterns = {"/editIssue"})
public class editIssue extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // if -1 we are creating a new Issue so show a blank form 
        // else get the Issue by the id and fill in for updating
        RequestDispatcher dispatcher;

        int issue_id = Integer.parseInt(request.getParameter("id"));
        
        response.setContentType("text/html;charset=UTF-8");
        request.setAttribute("appList", AppListDA.getAppList());
        request.setAttribute("priList", PriorityListDA.getAppList());
        request.setAttribute("usrList", UserListDA.getUserList());
        request.setAttribute("statList", StatusListDA.getStatusList());
 
        Issue activeIssue;
        /* new Issue form = blank */
        if (issue_id != -1) {
            /*Load the Issue from the DB when we're editing */
            activeIssue = IssueListDA.getIssue(issue_id);
        } 
        else{
            /* Create a blank Issue when we're not editing */
            activeIssue = new Issue();
        }
        
        /* Keep the activeIssue */
        request.getSession().setAttribute(SessionAttributes.getActiveIssueName(), activeIssue);
        request.setAttribute("activeIssue", activeIssue);
 
        //Forward to JSP
        dispatcher = getServletConfig().getServletContext().getRequestDispatcher("/editIssue.jsp");
        dispatcher.forward(request,response);
    }

        @Override
        public String getServletInfo() {
        return "Create defect issue form(s) for create new & edit existing";
        }// </editor-fold>

    }
